package com.xcw.strategy.handlerService;

import com.xcw.strategy.Handle.AbstractHandler;
import com.xcw.strategy.util.BeanTool;

import java.util.Map;

/**
 * @Author bhx
 * @Date 2022/7/18 1:29
 * @Description TODO
 */
public class HandlerContext {
    private Map<String,Class> handlerMap;

    public HandlerContext(Map<String, Class> handlerMap) {
        this.handlerMap = handlerMap;
    }

    public AbstractHandler getInstance(String type){
        Class clazz = handlerMap.get(type);
        if (clazz == null){
            throw new IllegalArgumentException("not find handler  for type " + type);
        }
        return (AbstractHandler) BeanTool.getBean(clazz);
    }
}
